package io.renren.modules.archive.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.renren.common.utils.StringUtils;
import io.renren.datasource.annotation.DataSource;
import io.renren.modules.archive.dao.MeetingtypeDao;
import io.renren.modules.archive.entity.ArchiveInfoEntity;
import io.renren.modules.archive.entity.JgsyCommonEntity;
import io.renren.modules.archive.entity.MeetingtypeEntity;
import io.renren.modules.archive.service.MeetingtypeService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;


@Service("meetingtypeService")
public class MeetingtypeServiceImpl extends ServiceImpl<MeetingtypeDao, MeetingtypeEntity> implements MeetingtypeService {

    @Autowired
    private MeetingtypeDao meetingtypeDao;



    public List<MeetingtypeEntity> selectMeetingTypeList(MeetingtypeEntity meetingtypeEntity){

        LambdaQueryWrapper<MeetingtypeEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(meetingtypeEntity.getMeetingtypeNd()),MeetingtypeEntity::getMeetingtypeNd,meetingtypeEntity.getMeetingtypeNd())
                .eq(StringUtils.isNotBlank(meetingtypeEntity.getMeetingtypeJg()),MeetingtypeEntity::getMeetingtypeJg,meetingtypeEntity.getMeetingtypeJg())
                .eq(StringUtils.isNotBlank(meetingtypeEntity.getOnesxlx()),MeetingtypeEntity::getOnesxlx,meetingtypeEntity.getOnesxlx())
                .eq(StringUtils.isNotBlank(meetingtypeEntity.getTwosxlx()),MeetingtypeEntity::getTwosxlx,meetingtypeEntity.getTwosxlx())
                .eq(StringUtils.isNotBlank(meetingtypeEntity.getThreesxlx()),MeetingtypeEntity::getThreesxlx,meetingtypeEntity.getThreesxlx())
                .eq(StringUtils.isNotBlank(meetingtypeEntity.getFoursxlx()),MeetingtypeEntity::getFoursxlx,meetingtypeEntity.getFoursxlx());
        return meetingtypeDao.selectList(lambdaQueryWrapper);

    }





    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        //根据文件名称查询
        String value = (String) params.get("key");
        String search = (String) params.get("search");
        String meetingtypeNd = (String) params.get("meetingtypeNd");
        String meetingtypeJg = (String) params.get("meetingtypeJg");
        String onesxlx = (String) params.get("onesxlx");
        String twosxlx = (String) params.get("twosxlx");
        String threesxlx = (String) params.get("threesxlx");


        IPage<MeetingtypeEntity> page = this.page(
                new Query<MeetingtypeEntity>().getPage(params),
                new QueryWrapper<MeetingtypeEntity>()
                        .like(StringUtils.isNotBlank(value), search, value)
                        .eq(StringUtils.isNotBlank(meetingtypeNd), "MEETINGTYPE_ND", meetingtypeNd)
                        .eq(StringUtils.isNotBlank(meetingtypeJg), "MEETINGTYPE_JG", meetingtypeJg)
                        .eq(StringUtils.isNotBlank(onesxlx), "ONESXLX", onesxlx)
                        .eq(StringUtils.isNotBlank(twosxlx), "TWOSXLX", twosxlx)
                        .eq(StringUtils.isNotBlank(threesxlx), "THREESXLX", threesxlx)
                        .orderByAsc("FOURSXLX")
        );

        return new PageUtils(page);
    }

    @Override
    @DataSource("smz")
    public List<JgsyCommonEntity> getJgsyName(String queryString) {

        return meetingtypeDao.getJgsyName(queryString);
    }

    @Override
    @DataSource("smz")
    public String getJgsyNameByCode(String jgsyCode) {
        return meetingtypeDao.getJgsyNameByCode(jgsyCode);
    }

}